Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
	''' <summary>
	''' Strongly-typed collection for the PollQuestions class.
	''' </summary>
	<Serializable> _
	Public Partial Class PollQuestionsCollection 
	Inherits ActiveList(Of PollQuestions, PollQuestionsCollection)
	    Public Sub New()
		End Sub
	End Class
	''' <summary>
	''' This is an ActiveRecord class which wraps the PollQuestions table.
	''' </summary>
	<Serializable> _
	Public Partial Class PollQuestions 
	Inherits ActiveRecord(Of PollQuestions)
		#Region ".ctors and Default Settings"
		
		Public Sub New()
			SetSQLProps()
			InitSetDefaults()
			MarkNew()
		End Sub
		
		Public Sub New(ByVal useDatabaseDefaults As Boolean)
			SetSQLProps()
			If useDatabaseDefaults = True Then
				ForceDefaults()
			End If
			MarkNew()
		End Sub
		Public Sub New(ByVal keyID As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByKey(keyID)
		End Sub
		Public Sub New(ByVal columnName As String, ByVal columnValue As Object)
			SetSQLProps()
			InitSetDefaults()
			LoadByParam(columnName,columnValue)
		End Sub
		Private Sub InitSetDefaults()
			SetDefaults()
		End Sub
		
		Protected Shared Sub SetSQLProps()
			GetTableSchema()
		End Sub
		#End Region
		
		#Region "Schema and Query Accessor"
		
		Public Shared ReadOnly Property Schema() As TableSchema.Table
			Get
				If BaseSchema Is Nothing Then
					SetSQLProps()
				End If
				Return BaseSchema
			End Get
		End Property
		Private Shared Sub GetTableSchema()
			If (Not IsSchemaInitialized) Then
				'Schema declaration
				Dim schema As TableSchema.Table = New TableSchema.Table("PollQuestions", TableType.Table, DataService.GetInstance("ClubStarterKitData"))
				schema.Columns = New TableSchema.TableColumnCollection()
				schema.SchemaName = "dbo"
				'columns
				
                
                Dim colvarPollId As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarPollId.ColumnName = "PollId"
                colvarPollId.DataType = DbType.Guid
                colvarPollId.MaxLength = 0
                colvarPollId.AutoIncrement = false
                colvarPollId.IsNullable = false
                colvarPollId.IsPrimaryKey = true
                colvarPollId.IsForeignKey = false
                colvarPollId.IsReadOnly = false
                
                
                schema.Columns.Add(colvarPollId)
                
                Dim colvarQuestion As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarQuestion.ColumnName = "Question"
                colvarQuestion.DataType = DbType.String
                colvarQuestion.MaxLength = 256
                colvarQuestion.AutoIncrement = false
                colvarQuestion.IsNullable = false
                colvarQuestion.IsPrimaryKey = false
                colvarQuestion.IsForeignKey = false
                colvarQuestion.IsReadOnly = false
                
                
                schema.Columns.Add(colvarQuestion)
                
                Dim colvarCreationDate As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarCreationDate.ColumnName = "CreationDate"
                colvarCreationDate.DataType = DbType.DateTime
                colvarCreationDate.MaxLength = 0
                colvarCreationDate.AutoIncrement = false
                colvarCreationDate.IsNullable = false
                colvarCreationDate.IsPrimaryKey = false
                colvarCreationDate.IsForeignKey = false
                colvarCreationDate.IsReadOnly = false
                
                
                schema.Columns.Add(colvarCreationDate)
                
                Dim colvarMemberid As TableSchema.TableColumn = New TableSchema.TableColumn(schema)
                colvarMemberid.ColumnName = "memberid"
                colvarMemberid.DataType = DbType.Guid
                colvarMemberid.MaxLength = 0
                colvarMemberid.AutoIncrement = false
                colvarMemberid.IsNullable = true
                colvarMemberid.IsPrimaryKey = false
                colvarMemberid.IsForeignKey = false
                colvarMemberid.IsReadOnly = false
                
                
                schema.Columns.Add(colvarMemberid)
                
				BaseSchema = schema
				
				'add this schema to the provider
                'so we can query it later
                DataService.Providers("ClubStarterKitData").AddSchema("PollQuestions",schema)
			End If
		End Sub
		Public Shared Function CreateQuery() As Query
			Return New Query(Schema)
		End Function
		
		#End Region
		
		#Region "Props"
	
          
        <XmlAttribute("PollId")> _
        Public Property PollId As Guid 
			Get
				Return GetColumnValue(Of Guid)("PollId")
			End Get
		    
			Set
				SetColumnValue("PollId", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Question")> _
        Public Property Question As String 
			Get
				Return GetColumnValue(Of String)("Question")
			End Get
		    
			Set
				SetColumnValue("Question", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("CreationDate")> _
        Public Property CreationDate As DateTime 
			Get
				Return GetColumnValue(Of DateTime)("CreationDate")
			End Get
		    
			Set
				SetColumnValue("CreationDate", Value)
			End Set
		End Property
		
		
		  
        <XmlAttribute("Memberid")> _
        Public Property Memberid As Nullable(Of Guid) 
			Get
				Return GetColumnValue(Of Nullable(Of Guid))("memberid")
			End Get
		    
			Set
				SetColumnValue("memberid", Value)
			End Set
		End Property
		
		
		
		
		#End Region
		
		
			    
	    
	    #Region "PrimaryKey Methods"
	    
			Public Function PollAnswersRecords() As Data.PollAnswersCollection 
	
				Return New Data.PollAnswersCollection().Where(PollAnswers.Columns.QuestionId, PollId).Load()
	
			End Function
			
			Public Function PollReactionsRecords() As Data.PollReactionsCollection 
	
				Return New Data.PollReactionsCollection().Where(PollReactions.Columns.PollId, PollId).Load()
	
			End Function
			
		#End Region
		
		
		
		
		
		
	    
	    'no foreign key tables defined (0)
	    
		
	    
	    'no ManyToMany tables defined (0)
	    
		
		#Region "ObjectDataSource support"
		
		''' <summary>
		''' Inserts a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Insert(ByVal varPollId As Guid,ByVal varQuestion As String,ByVal varCreationDate As DateTime,ByVal varMemberid As Nullable(Of Guid))
			Dim item As PollQuestions = New PollQuestions()
			
            item.PollId = varPollId
            
            item.Question = varQuestion
            
            item.CreationDate = varCreationDate
            
            item.Memberid = varMemberid
            
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		''' <summary>
		''' Updates a record, can be used with the Object Data Source
		''' </summary>
		Public Shared Sub Update(ByVal varPollId As Guid,ByVal varQuestion As String,ByVal varCreationDate As DateTime,ByVal varMemberid As Nullable(Of Guid))
			Dim item As PollQuestions = New PollQuestions()
		    
                item.PollId = varPollId
				
                item.Question = varQuestion
				
                item.CreationDate = varCreationDate
				
                item.Memberid = varMemberid
				
			item.IsNew = False
			If Not System.Web.HttpContext.Current Is Nothing Then
				item.Save(System.Web.HttpContext.Current.User.Identity.Name)
			Else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name)
			End If
		End Sub
		#End Region
		#Region "Columns Struct"
		Public Structure Columns
			Dim x as Integer
			
            Public Shared PollId As String = "PollId"
            
            Public Shared Question As String = "Question"
            
            Public Shared CreationDate As String = "CreationDate"
            
            Public Shared Memberid As String = "memberid"
            
		End Structure
		#End Region
	End Class
End Namespace
